Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add previous period hash to proofs and roots if present #166

Merged
merged 4 commits into from
Dec 23, 2019

Conversation

TheReturnOfJan
Copy link
Contributor

Resolves: #165

block = new Block(i).addTx(Tx.deposit(i, value, ADDR, color));
blocks.push(block);
} else {
blocks.push(new Block(i));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose to add empty blocks? 🤔

const period = new Period("'0x8b04de057fe524a3118eb7c8e14a2e55323c67fd7b6080583d1047b700b2d674'", blocks);
period.setValidatorData(slotId, ADDR);
const proof = period.proof(transfer);
expect(proof).to.eql([
Copy link
Member

@troggy troggy Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is not checking that prevHash is included in the proof, no?

How about that:

  1. period = new Period(prevHash, blocks)
  2. const proof1 = period.proof(transfer)
  3. period = new Period(someOtherPrevHash, blocks)
  4. const proof2 = period.proof(transfer)
  5. expect(proof1).not.equal(proof2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or better check for prevHash inclusion?

block = new Block(31).addTx(transfer);
blocks.push(block);

const period = new Period("'0x8b04de057fe524a3118eb7c8e14a2e55323c67fd7b6080583d1047b700b2d674'", blocks);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra quotes?

Copy link
Member

@troggy troggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation looks good 👍

Left some questions about tests

@troggy
Copy link
Member

troggy commented Dec 23, 2019

Suggesting the following change for this PR: #167

periodAfter.usePrevPeriod();

const proof = periodAfter.prevPeriodProof();
expect(Period.verifyPrevPeriodProof(proof)).to.eql(periodAfter.periodRoot());
Copy link
Member

@troggy troggy Dec 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't really checking that period.periodRoot() was used in proof, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below.

lib/period.js Outdated
}

// returns current period
static verifyPrevPeriodProof(proof) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name is misleading IMO. It is not verifying anything, but rather calculating period root for the proof

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is because in solidity the verify method just computes the edges if the walk and verifies they reference one another. See new commit for clarification.

Copy link
Member

@troggy troggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left couple of questions
+
suggesting to add this change to make API better: #167

troggy and others added 2 commits December 23, 2019 18:07
* chore: rework Period object constructor

1. Set `usePrev` by default. BREAKING change
2. Accept optional third arguments of `PeriodOptions` type:
allows to set validator data and set `usePrev` to false for legacy proofs.

* docs: add period hashing schema
@troggy troggy changed the title Add previous period to proofs and roots if present. feat: add previous period hash to proofs and roots if present Dec 23, 2019
Copy link
Member

@troggy troggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@troggy troggy merged commit 141a564 into master Dec 23, 2019
@troggy troggy deleted the addPrevPeriodToProofs branch December 23, 2019 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add prevHash to period proof
2 participants